#pragma once

#include <WebSocket/types.h>
#include "TcpClientTask.h"
#include "../types.h"

namespace Call
{

    struct TcpHandleTask : public WS::Thread
    {
        WS::TcpServer tcpServer;
        std::vector<TcpClientTask*> m_tasks;
        std::mutex m_task_mutex;

        int CountLinkNum();

        bool Create();
        void Run();
        bool HasCreateTask(const std::string &host);
        TcpClientTask *RegisterHost(const WS::TcpSocket &socket);

        void LockTaskList();
        ~TcpHandleTask();

    private:
        void OnAccept(const WS::TcpSocket &socket);
    };
};
